//
//  ImageTableViewCell.m
//  网易新闻
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ImageTableViewCell.h"
#import "Duanzi.h"
#import "Highet.h"
@interface ImageTableViewCell()
@property (nonatomic,retain)UIImageView *imagevi;
@property(nonatomic,retain)UILabel *label;
@end


@implementation ImageTableViewCell
-(void)dealloc{
    [_imagevi release];
    [super dealloc];
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imagevi = [[UIImageView alloc]init];
        self.label  = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.imagevi];
        [self.contentView addSubview:self.label];
        [_label release];
        
        [_imagevi release];
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
   
    CGFloat labelHeight = [Highet heightWith:self.duanzi.digest];
    
    self.label.frame = CGRectMake(0,0, self.contentView.bounds.size.width, labelHeight);
    
    self.label.backgroundColor = [UIColor whiteColor];
    
    
    self.label.numberOfLines = 0;
    
}

-(void)setDuanzi:(Duanzi *)duanzi{
    if (_duanzi != duanzi) {
        [_duanzi release];
        _duanzi  = [duanzi retain];
    }
    CGFloat imageHeight  = [Highet imageHeightWithUrlstring:self.duanzi.imgsrc];
    self.imagevi.frame = CGRectMake(20, 0, self.contentView.frame.size.width-40, imageHeight);
    self.imagevi.backgroundColor = [UIColor blueColor];
    
    
    
    NSURL *url = [ NSURL URLWithString:duanzi.imgsrc];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    _imagevi.image  = image;
    _label.text  = duanzi.digest;
    _label.font = [UIFont systemFontOfSize:20];

}


@end
